package com.share.example.selenium.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.share.example.selenium.mapper.WorkCalendarMapper;
import com.share.example.selenium.model.db.WorkCalendar;
import com.share.example.selenium.service.IWorkCalendarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author author
 * @since 2023-09-28
 */
@Service
public class WorkCalendarServiceImpl extends ServiceImpl<WorkCalendarMapper, WorkCalendar> implements IWorkCalendarService {
    private Map<String, Map<String, String>> calendarMap = new HashMap();

    @Autowired
    private WorkCalendarMapper workCalendarMapper;


    @Override
    public Map<String, String> mapByBizCode(String bizCode) {
        return calendarMap.get(bizCode);
    }

    @Override
    public Map<String, Map<String, String>> initCalendarMap() {
        List<WorkCalendar> tmpList = workCalendarMapper.selectList(null);
        Map<String, Map<String, String>> tmpMap = new HashMap();
        for (WorkCalendar item : tmpList) {
            String bizCode = item.getBizCode();
            Map<String, String> bizMap = tmpMap.get(bizCode);
            if (bizMap == null) {
                bizMap = new HashMap<>();
                tmpMap.put(bizCode, bizMap);
            }

            bizMap.put(item.getWriteDate(), item.getBehave());
        }

        if (tmpMap.size() > 0) {
            this.calendarMap = tmpMap;
        }

        return tmpMap;
    }

}
